import { request } from '@/utils/request'
import type { News, NewsQuery } from '@/types/common'

export const newsApi = {
  // 获取资讯列表（分页）
  getNewsPage(params: Omit<NewsQuery, 'orderBy'> & { orderBy?: string } = {}) {
    return request.get<{ list: News[], total: number, page: number, size: number, totalPages: number }>('/news/list', { params })
  },

  // 获取资讯详情
  getNewsDetail(id: number) {
    return request.get<News>(`/news/${id}`)
  },

  // 获取推荐资讯
  getRecommendNews(limit = 5) {
    return request.get<News[]>('/news/recommend', { 
      params: { limit }
    })
  },

  // 获取置顶资讯
  getTopNews(limit = 5) {
    return request.get<News[]>('/news/top', { 
      params: { limit }
    })
  },

  // 搜索资讯
  searchNews(keyword: string, page = 1, size = 10) {
    return request.get<{ list: News[], total: number, page: number, size: number, totalPages: number }>('/news/search', {
      params: { keyword, page, size }
    })
  },

  // 获取类型统计
  getTypeStats() {
    return request.get('/news/type-stats')
  }
}
